/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Thread;

import ObjectFileOptions.ObjectFile;
import ObjectFileOptions.ObjectFileOption;
import Packets.pkValue;
import StaticClass.ArrSocket;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Oho
 */
public class ThreadChat extends Thread {

    ObjectInputStream in;
    ObjectOutputStream out;
    private String Command;
    private Socket sk;
    ServerSocket sv = null;
    int port;

    public ThreadChat(int port) throws IOException {
        this.port = port;


    }

    public ThreadChat(ObjectInputStream inp,ObjectOutputStream out) {

        this.in = inp;
        this.out = out;

    }

    public ThreadChat(ObjectInputStream in, String command) {
        this.in = in;
        this.Command = command;
    }

    public ThreadChat() {
    }

    public synchronized void ThreadRead() {
        //  try {



     
        ObjectFileOption ob = new ObjectFile(sk, in, out, this);
        ob.progessRead();
        // }

//        }
    }

    public void ThreadWrite(pkValue pk) throws IOException {
        if (out == null) {
        }

        ObjectFileOption ob = new ObjectFile(sk, in, out, this);
        ob.progessWrite(sk, pk);


    }
    
    public synchronized void Read() {
    //    try {
          
            ArrSocket.ArrChat.add(this);
    //        new SendComputerName(in, out).start();
            //in = new ObjectInputStream(sk.getInputStream());
            //out = new ObjectOutputStream(sk.getOutputStream()); 

            //sv = new ServerSocket(port);
            while (true) {
                //new SendComputerName(in, out).start();
                //            sk = sv.accept();
                ThreadRead();

                //sk = sv.accept();

                //os = client.getOutputStream();

         //   }
        } 

    }

    @Override
    public void run() {
        Read();
    }

    /**
     * @return the Command
     */
    public String getCommand() {
        return Command;
    }

    /**
     * @param Command the Command to set
     */
    public void setCommand(String Command) {
        this.Command = Command;
    }

    /**
     * @return the sk
     */
    public Socket getSk() {
        return sk;
    }

    /**
     * @param sk the sk to set
     */
    public void setSk(Socket sk) {
        this.sk = sk;
    }
}
